

import 'package:flutter/material.dart';
import 'package:preview_family_bucket/picture/picture_view_single_page.dart';
import 'package:preview_family_bucket/picture/picture_view_mult_page.dart';
import 'package:preview_family_bucket/preview_family_bucket.dart';
// import 'package:dgg_flutter_photocamera/photocamera_plugin.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
    );
  }
}

Future <bool> getResult()async{
  return await false;
}

class HomePage extends StatefulWidget{
  @override
    HomePageState createState(){
      return HomePageState();
    }
}

class HomePageState extends State<HomePage> {
  int currentIndex = 1;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('预览全家桶'),
      ),
      body: Container(
        alignment: Alignment.center,
        child: Column(
          children: <Widget>[
            RaisedButton(
              child: Text("简单图片预览"),
              onPressed: () {
                var picUrl =
                    "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574937225930&di=f3ef95b2517d44ef4e603e7980d959a3&imgtype=0&src=http%3A%2F%2Fwww.yosoar110.com%2FupLoad%2Fnews%2Fmonth_1508%2F201508191107552885.jpg";
                //导航到新路由
                Navigator.push(context, MaterialPageRoute(builder: (context) {
                  return PictureViewSinglePage(
                    picUrl,
                    contentBgColor: Colors.white,
                  );
                }));
              },
            ),
            RaisedButton(
              child: Text("多图片预览"),
              onPressed: () {
                List<String> picUrls = List();
                picUrls.add(
                    "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574939079429&di=8b43fcdf8d3b6f117658105d4eff2fe0&imgtype=0&src=http%3A%2F%2Fimg.mp.itc.cn%2Fupload%2F20170802%2F1a0262813af546b982f485f8bb414195_th.jpg");
                picUrls.add(
                    "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574939091914&di=a2323f20c47bd2c0aea41357f87813d3&imgtype=0&src=http%3A%2F%2Fe0.ifengimg.com%2F04%2F2018%2F1205%2FB56D39610FA63C93EFCCCCC41BD1306D88B1101C_size25_w600_h300.jpeg");
                picUrls.add(
                    "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574939113686&di=f230ab42729bdd57c876c4bfa3e5f5fa&imgtype=0&src=http%3A%2F%2Fpicture01.52hrttpic.com%2Fimage%2FinfoImage%2F201903%2F18%2FG1552634874240.jpeg%3F640x427");
                picUrls.add(
                    "https://n.sinaimg.cn/tech/transform/760/w500h260/20191127/3794-iixntzz6766792.gif");
                //导航到新路由
                Navigator.push(context, MaterialPageRoute(builder: (context) {
                  return PictureViewMultPage(
                    picUrls,
                    contentBgColor: Colors.white,
                  );
                }));
              },
            ),
            RaisedButton(
              child: Text("多图片预览---支持旋转、删除、缩放"),
              onPressed: () {
                Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => GalleryPhotoViewWrapper(
                          galleryItems: galleryItems,
                          backgroundDecoration: const BoxDecoration(
                            color: Colors.white,
                          ),
                                      initialIndex: 0,
                          scrollDirection: Axis.horizontal,
                          choseDeleteImageCallbck: (id){
                            Future<bool> iss = showDialogss(context,currentIndex);
                            if(iss!=null){
                              return iss;
                            }else{
                              
                            }
                          },
                          logoWidget: Positioned(
                                      top:20,
                                      right: 20,
                                      child: Image.asset('images/WechatIMG89.jpeg',width: 90,height: 90)
                                      ),
                          pageNumWidgetCallback: (index){
                              return Positioned(
                                      top:30,
                                      left: 100,
                                      child: Text(
                                        "${index+1} /${galleryItems.length}",
                                        style: const TextStyle(
                                          color: Colors.white,
                                          fontSize: 17.0,
                                          decoration: null,
                                        ),
                                      ),
                                      );
                          },
                          isDeleteContainer: Container(
                            margin: EdgeInsets.only(top:30),
                            padding: const EdgeInsets.all(20.0),
                            child: Container(
                                  width: 50,
                                  height: 30,
                                  alignment: Alignment.center,
                                  child: Text(
                                    "删除",
                                    style: const TextStyle(
                                      color: Colors.white,
                                      fontSize: 12.0,
                                      // decoration: null,
                                    ),
                                  ),
                                )
                          ) 
                        ),
                      ),
                    );
              }
            ),
          ],
        ),
      ),
    );
  }
}

Future<bool> showDialogss(BuildContext context,int index) async {
  Future<bool> isss =  showDialog<bool>(
    context: context,
    barrierDismissible: false,
    builder: (BuildContext context) {
      return new AlertDialog(
        backgroundColor:Colors.red,
        title: new Text(
          '请确认当前操作',
          style: TextStyle(fontWeight: FontWeight.bold),
        ),
        content: new SingleChildScrollView(
          child: Text('确认后，将从当前好友列表中删除该对象目前不支持找回，请慎重操作'),
        ),
        actions: <Widget>[
          new FlatButton(
            child: new Text('取消'),
            onPressed: () {
              Navigator.of(context).pop(false);
            },
          ),
          new FlatButton(
            child: new Text('确认'),
            onPressed: () {
              Navigator.of(context).pop(true);
            },
          )
        ],
      );
    },
  ).then((val) {
    return  val;
    print('${val}=========val');
  });
  return isss;
}

// List<GalleryExampleItem> galleryItems = <GalleryExampleItem>[
//   GalleryExampleItem(
//     id: "tag1",
//     resource: "assets/gallery1.jpg",
//   ),
//   GalleryExampleItem(id: "tag2", resource: "assets/firefox.svg", isSvg: true),
//   GalleryExampleItem(
//     id: "tag3",
//     resource: "assets/gallery2.jpg",
//   ),
//   GalleryExampleItem(
//     id: "tag4",
//     resource: "assets/gallery3.jpg",
//   ),
// ];